package master.ghrm.constants;

import java.util.ArrayList;
import java.util.List;

public enum GradingConst {

	NOT_GRADED(0, "Not graded"), NOT_FAMILIAR(1, "Not familiar"), FAMILIAR(2, "Familiar"), FAIR(3, "Fair"), GOOD(4,
			"Good"), VERY_GOOD(5, "Very good"), EXCELLENT(6, "Excellent");

	private int identifier;
	private String label;

	private GradingConst(int anIdentifier, String aLabel) {
		identifier = anIdentifier;
		label = aLabel;
	}

	public static List<GradingConst> getAllGrades() {
		List<GradingConst> allGrades = new ArrayList<GradingConst>();

		GradingConst[] values = values();
		for (int i = 0; i < values.length; i++) {
			allGrades.add(values[i]);
		}

		return allGrades;
	}

	public static String getDefaultGrade() {
		return NOT_GRADED.getLabel();
	}

	public static List<GradingConst> getGradesHigherOrEquealTo(String gradeName) {
		List<GradingConst> retVal = new ArrayList<GradingConst>();

		GradingConst grade = resolveByName(gradeName);

		switch (grade.getIdentifier()) {
		case 0:
			retVal.add(NOT_GRADED);
		case 1:
			retVal.add(NOT_FAMILIAR);
		case 2:
			retVal.add(FAMILIAR);
		case 3:
			retVal.add(FAIR);
		case 4:
			retVal.add(GOOD);
		case 5:
			retVal.add(VERY_GOOD);
		case 6:
			retVal.add(EXCELLENT);
			break;
		}

		return retVal;
	}

	public static List<GradingConst> getGradesHigherOrEquealTo(GradingConst grade) {
		List<GradingConst> retVal = new ArrayList<GradingConst>();

		switch (grade.getIdentifier()) {
		case 0:
			retVal.add(NOT_GRADED);
		case 1:
			retVal.add(NOT_FAMILIAR);
		case 2:
			retVal.add(FAMILIAR);
		case 3:
			retVal.add(FAIR);
		case 4:
			retVal.add(GOOD);
		case 5:
			retVal.add(VERY_GOOD);
		case 6:
			retVal.add(EXCELLENT);
			break;
		}

		return retVal;
	}

	public static GradingConst resolveByName(String gradeName) {
		if (EXCELLENT.label.equalsIgnoreCase(gradeName)) {
			return EXCELLENT;
		}

		if (VERY_GOOD.label.equalsIgnoreCase(gradeName)) {
			return VERY_GOOD;
		}

		if (GOOD.label.equalsIgnoreCase(gradeName)) {
			return GOOD;
		}

		if (FAIR.label.equalsIgnoreCase(gradeName)) {
			return FAIR;
		}

		if (FAMILIAR.label.equalsIgnoreCase(gradeName)) {
			return FAMILIAR;
		}

		if (NOT_FAMILIAR.label.equalsIgnoreCase(gradeName)) {
			return NOT_FAMILIAR;
		}

		return NOT_GRADED;
	}

	public int getIdentifier() {
		return identifier;
	}

	public String getLabel() {
		return label;
	}

}
